<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/7/26
  Time: 12:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <!-- If you'd like to support IE8 (for Video.js versions prior to v7) -->

</head>

<body>
<video
        id="myPlayer"
        autoplay
        src=""
        width="1000"
        height="500"
        controls
        playsInline
        webkit-playsinline
>
</video>
<%--<video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="264"--%>
       <%--poster="http://video-js.zencoder.com/oceans-clip.png"--%>
       <%--data-setup="{}">--%>

    <%--<source src="https://hls01open.ys7.com/openlive/8c24ac1257c8434685ca7a0c989ae37f.hd.m3u8" type='application/x-mpegURL' />--%>
<%--</video>--%>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/ezuikit.js"></script>
<%--<script type="text/javascript">--%>
    <%--var myPlayer = videojs('example_video_1');--%>
    <%--videojs("example_video_1").ready(function(){--%>
        <%--var myPlayer = this;--%>
        <%--myPlayer.play();--%>
    <%--});--%>
<%--</script>--%>
<script>
    var serial = ''
    var Token = 'at.djmrc1l76kk8q9r26nvai1w77yc8z99w-1e6jr6wq87-1tbux0a-rqqqnkwgz';
    function child(videotid,videoUrl) {
        layui.use(['table', 'form', 'layer'], function () {
            var $ = layui.$
                , table = layui.table
                , layer = layui.layer
                , form = layui.form
            var data = {
                deviceSerial: 'E42012633',
                channelNo: '1'
            }

            data.deviceSerial = videotid
            serial = videotid
            getToken();
            //eg:videoUrl:ezopen://open.ys7.com/086f83b73aa74dc39a053aadb50b58fb.live
            $('#myPlayer').attr("src", videoUrl);
            var player = new EZUIKit.EZUIPlayer('myPlayer');
        });
    }

    var control = function (direction) {
        var data = {}
        data.accessToken = Token;
        data.direction = direction;//控制方式
        data.speed = '1';//转动速度
        data.deviceSerial = serial
        data.channelNo = 1
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.post('https://open.ys7.com/api/lapp/device/ptz/start', data, function (res) {

                if (res.code == 200) {
                    layer.msg("摄像头移动中，请稍后", {time: 9000});
                    sleep(50);
                    stop();
                } else if (res.code == 10002) {
                    getToken();
                } else {

                }
            }, 'json');
            return false;
        });
    }


    var getToken = function () {
        var data1 = {appKey: 'f9cdc3af74d148d18e12b42bb4298b8b', appSecret: 'a16cae3a4495c0b291951dc6efd742fb'};
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.post(' https://open.ys7.com/api/lapp/token/get', data1, function (res) {
                if (res.code == 200) {
                    Token = res.data.accessToken;
                } else {
                    layer.msg(res.msg, {time: 2000});
                }
            }, 'json');
            return false;
        });

    }

    //停止转动
    var stop = function () {
        var data = {}
        data.accessToken = Token;


        data.deviceSerial = serial
        data.channelNo = 1
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.post('https://open.ys7.com/api/lapp/device/ptz/stop', data, function (res) {
                if (res.code == 200) {

                } else {
                    layer.msg(res.msg, {time: 2000});
                }
            }, 'json');
            return false;
        });
    }

    function sleep(n) {
        var start = new Date().getTime();
        //  console.log('休眠前：' + start);
        while (true) {
            if (new Date().getTime() - start > n) {
                break;
            }
        }
        // console.log('休眠后：' + new Date().getTime());
    }
</script>
<script type="text/javascript">
 //   $('#init').click(function () {
       // var url = $('#url').val().trim();
      //  var url = 'https://hls01open.ys7.com/openlive/8c24ac1257c8434685ca7a0c989ae37f.hd.m3u8'

 var url = 'https://hls01open.ys7.com/openlive/902f94aba8ef42ae8ae05d2250df5e66.hd.m3u8'
      // var url = 'ezopen://hls01open.ys7.com/openlive/902f94aba8ef42ae8ae05d2250df5e66.hd.m3u8';
        $('#myPlayer').attr("src", url);
        var player = new EZUIKit.EZUIPlayer('myPlayer');
        // 日志
        player.on('log', log);

//        function log(str) {
//            var div = document.createElement('DIV');
//            div.innerHTML = (new Date()).Format('yyyy-MM-dd hh:mm:ss.S') + JSON.stringify(str);
//            document.body.appendChild(div);
//        }
//        $("#stop").click(function () {
//            player.stop();
//        })
//    });
</script>

</body>
